package com.ymatou.iapi.im.testcase;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.google.gson.JsonObject;
import com.ymatou.iapi.im.parameter.SendMessageToSellerBean;
import com.ymatou.iapi.im.parameter.SetBizStatusBean;
import com.ymatou.iapi.im.service.SetBizStatusCall;
import com.ymatou.iapi.userregister.parameter.UserRegisterInfoRequestDtoBean;
import com.ymatou.iapi.userregister.service.UserRegisterInfoRequestDtoCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.*;
import com.ymt.utils.tag.*;
import com.ymttest.business.service.ImCallService;
import com.ymttest.business.service.JUserCallService;
import com.ymttest.database.model.YmtMessage;
import com.ymttest.database.sqlwapper.ImDefaultWapper;
import com.ymttest.utils.EnvSetup;
/**
*设置私信的业务状态
*FreeMaker Template自动生成代码
*/
@TestSuite
public class Ts_SetBizStatus{
	private static SetBizStatusBean setbizstatusBean;
	private static SetBizStatusCall setbizstatusCall;
	private static int sellerId = Integer.parseInt(EnvSetup.getData("autotest_seller1"));
	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("设置私信的业务状态");
	}

	@Before
	public void caseUp() {
		setbizstatusBean=new SetBizStatusBean();
		setbizstatusCall=new SetBizStatusCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(setbizstatusCall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}
	@Test
	@Category({P1.class})
	@TestCase
	public void Tc_SetBizStatus_001() {
		Logger.start(true,"设置私信的业务状态成功");
		try {
			UserRegisterInfoRequestDtoBean regbean = JUserCallService.initUserRegisterInfoRequestDtoBean();
			UserRegisterInfoRequestDtoCall urrc = JUserCallService.UserRegisterInfoRequestDtoCall(regbean);
			Integer userId = urrc.getUserid();
			SendMessageToSellerBean sendMessageToSellerBean = ImCallService.initSendMessageToSellerBean(userId,sellerId,"你好，im");
			JsonObject jo = ImCallService.SendMessageToSeller(sendMessageToSellerBean);
			String messageId = jo.get("messageId").getAsString();
			setbizstatusBean.setBizStatus(1);
			setbizstatusBean.setMessageId(messageId);
			setbizstatusCall.setData(setbizstatusBean);
			setbizstatusCall.callService();			
			Logger.verifyEquals("Success", setbizstatusCall.getString("Status"), "验证Status");
			YmtMessage ymtMessage = new ImDefaultWapper().selectImInfo(messageId).get(0);
			Logger.verifyEquals(setbizstatusBean.getBizStatus(), ymtMessage.getBizStatus(), "验证getBizStatus");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetBizStatus_002() {
		Logger.start(true,"不输入messageId失败");
		try {
			setbizstatusBean.setBizStatus(1);
//			setbizstatusBean.setMessageId(messageId);
			setbizstatusCall.setData(setbizstatusBean);
			setbizstatusCall.callService();			
			Logger.verifyEquals("BussinessError", setbizstatusCall.getString("Status"), "验证Status");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
	@Test
	@Category({P2.class})
	@TestCase
	public void Tc_SetBizStatus_003() {
		Logger.start(true,"不输入bizStatus失败");
		try {
//			setbizstatusBean.setBizStatus(1);
			setbizstatusBean.setMessageId("1");
			setbizstatusCall.setData(setbizstatusBean);
			setbizstatusCall.callService();			
			Logger.verifyEquals("BussinessError", setbizstatusCall.getString("Status"), "验证Status");
			
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}